using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Skill1 : MonoBehaviour
{
    public float speed = 15.0f;
    public GameObject player;
    private bool candestory;
    public int atk=15;
    public enum EnemyPlayState
    {
        Skill1,
        Skill2,
        Skill3,
    }
    private EnemyPlayState curPlayState;
    public EnemyPlayState CurPlayState
    {
        get => curPlayState;
        set
        {
            curPlayState = value;
            switch (curPlayState)
            {
                case EnemyPlayState.Skill1:
                    break;
                case EnemyPlayState.Skill2:
                    break;
                case EnemyPlayState.Skill3:
                    break;
            }
        }
    }
    // Start is called before the first frame update
    void Start()
    {

    }
    private void Awake()
    {
        speed = 20f;
        candestory = false;
        player = GameObject.Find("Player").transform.gameObject;
        curPlayState = EnemyPlayState.Skill1;
    }
    // Update is called once per frame
    void Update()
    {
        StateOnUpdate();
    }

    private void StateOnUpdate()
    {

        if (CurPlayState == EnemyPlayState.Skill1)
        {
            SKILL1();
        }
        if (CurPlayState == EnemyPlayState.Skill2)
        {
            SKILL2();
        }
        else if (CurPlayState == EnemyPlayState.Skill3)
        {
            SKILL3();
        }
    }

    float cur1time = 0.75f;
    void SKILL1()
    {
        if(cur1time>0)
        {
            this.transform.Translate(transform.forward * speed * Time.deltaTime, Space.World);
            cur1time -= Time.deltaTime;
        }
        else
        {
            curPlayState = EnemyPlayState.Skill2;
        }
    }
    public float rotateSpeed = 100f;
    float cur2time = 5f;

    void SKILL2()
    {
        candestory = true;
        if (cur2time>0)
        {
            this.transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime, Space.World);
            cur2time -= Time.deltaTime;
        }
        else
        {
            transform.LookAt(player.transform.position);
            candestory = false;
            curPlayState = EnemyPlayState.Skill3;
        }
    }
    float waittime=0.2f;
    void SKILL3()
    {

        waittime -= Time.deltaTime;
        if(waittime<0)
        {
            this.transform.Translate(transform.forward * speed * 3f * Time.deltaTime, Space.World);
            Destroy(gameObject, 4f);
        }
    
    }



    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Bullet" && candestory==true)
        {
            Destroy(gameObject);
        }
        if (other.gameObject.tag == "Player" && candestory == false)
        {
            other.gameObject.GetComponent<Player_Control>().GetHurt(atk);

        }
    }
}
